function s = isscalarcell(c, t, nin)
% isscalarcell  - returns a boolean array with isscalar over cells
%
% FORMAT:       isc = isscalarcell(c [, t [, nin]])
%
% Input fields:
%
%       c           cell array
%       t           optional type requirement (matlab name)
%       nin         also rejects Inf/NaN scalar values
%
% Output fields:
%
%       isc         input-sized boolean array with isscalar(c{i,j,...})
%
% This is a MEX (c compiled) function for efficiency.

% Version:  v0.7g
% Build:    9100818
% Date:     Otc-08 2009, 6:22 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
   ~iscell(c)
    error( ...
        'BVQXtools:BadArgument', ...
        'Bad or missing argument.' ...
    );
end
if nargin < 2 || ...
   ~ischar(t) || ...
   ~any(strcmpi(t, ...
        {'char', 'double', 'int16', 'int32', 'int64', 'int8', ...
         'logical', 'single', 'uint16', 'uint32', 'uint64', 'uint8'}))
    t = '';
else
    t = lower(t(:)');
end
if nargin < 3 || ...
   ~islogical(nin) || ...
    numel(nin) ~= 1
    nin = false;
end

% create output
s = true(size(c));

% without anything special
if isempty(t)
    if ~nin

        % iterate
        for cc = 1:numel(c)

            % set value
            s(cc) = isscalar(c{cc});
        end

    % no inf/nan values
    else
        
        % iterate
        for cc = 1:numel(c)
            
            % set value
            s(cc) = (isscalar(c{cc}) && ...
               ~isinf(c{cc}) && ...
               ~isnan(c{cc}));
        end
    end

% type information requested
else
    
    % without inf/nan restriction
    if ~nin
        
        % iterate
        for cc = 1:numel(c)
            
            % set value
            s(cc) = (isscalar(c{cc}) && ...
                isa(c{cc}, t));
        end
        
    % with inf/nan restriction
    else
        
        % iterate
        for cc = 1:numel(c)
            
            % set value
            s(cc) = (isscalar(c{cc}) && ...
                isa(c{cc}, t) && ...
               ~isinf(c{cc}) && ...
               ~isnan(c{cc}));
        end
    end
end